package com.ysyx.ysyx_shareorder.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

/**
 * Created by IntelliJ IDEA.
 *
 * @description: xxxx接口/类
 * @author:郭宇轩
 * @create:2023/4/12 11:06
 */
@Configuration
public class RedisConfig {

    @Autowired
    private RedisConnectionFactory redisConnectionFactory;


//    @Bean
//    public RedisTemplate redisTemplate(){
//        RedisTemplate<Object,Object> redisObj = new RedisTemplate<>();
//        return redisObj;
//    }

    @Bean
    public RedisMessageListenerContainer redisMessageListenerContainer(){
        RedisMessageListenerContainer redisMessageListenerContainer = new RedisMessageListenerContainer();
        redisMessageListenerContainer.setConnectionFactory(redisConnectionFactory);
        return redisMessageListenerContainer;
    }

    @Bean
    public KeyExpirationEventMessageListener keyExpirationEventMessageListener(){
        return new KeyExpirationEventMessageListener(this.redisMessageListenerContainer());
    }



}
